package com.huang.controller;


import com.huang.clients.ProductClient;
import com.huang.entity.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {


    @Resource(name = "myRestTemplate")
    private RestTemplate restTemplate;

    @Autowired
    private ProductClient productClient;

    @Value("${server.port}")
    private int port;


    @GetMapping("/showMsg")
    public String showMessage(){
        System.out.println("进入用户服务");
        return "这是用户信息"+port;
    }

    @GetMapping("/showProductMsg")
    public String showProductMsg(){

        String forObject = restTemplate.getForObject("http://products/product/showMsg", String.class);
        System.out.println("调用成功");
        return forObject+port;

    }


    @GetMapping("/showMessageOpenFeign")
    public String showMessageOpenFeign(){
        System.out.println("进入openfeign");
        String s = this.productClient.showMessage();
        return s;
    }


    @GetMapping("/showMsgTestGetParam")
    public String showMessageGetParam(@RequestParam("msg") String msg){
        String s = this.productClient.showMessageGetParam(msg);
        return s;
    }

    @GetMapping("/addProduct")
    public Map<String,Object> addProduct(){
        Product product = new Product(123,"衣服",26.5,new Date());
        return this.productClient.addProduct(product);


    }
}
